<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
	<link rel="stylesheet" href="__CSS__/admin.css" media="all">
	<!--<script src="http://{$Think.config.google_map_url}" async="async"></script>-->
	<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

</head>
<style>
	.layui-upload-img {
		width: 100px;
	!important;
	}

	.addclassify {
		display: inline-block;
		width: 40px;
		height: 40px;
		border: 1px solid #666;
		line-height: 40px;
		border-radius: 40px;
		text-align: center;
		cursor: pointer;
	}

	#right {
		width: 200px;
		height: 300px;
		border: 1px solid #777;
		overflow-y: scroll;
	}

	.btns span {
		margin: 5px 10px;
	}

	.shi {
		text-align: center;
		font-size: 16px;
		margin: 10px 0;
	}

	.activity {
		background: #1E9FFF;
		color: white;
	}

	.tabs {
		/*border: 1px solid #868686;*/
		padding: 5px 40px;
	}
</style>

<body>
<div style="margin-top: 20px;">
</div>

<form class="layui-form" id="admin">

	<input type="hidden" id="classifyid" value="{$id}">
	<div id="classifybox">
		{volist name="specs" id="vo"}
		<div class="layui-form-item classifychild">
			<label class="layui-form-label">套餐规格</label>
			<div class="layui-input-inline person" style="width: 500px">
				<input type="hidden" name="specs_id" id="specs_id" value="{$vo.specs_id}">
				<div class="layui-input-inline" style="width: 400px;padding-bottom: 15px">
					<input name="specs_name" value="{$vo.specs_name}"  placeholder="规格名称" autocomplete="off" class="layui-input" type="text" lay-key="1">
				</div>
			</div>
			<div class="layui-form-item childs">
				<label class="layui-form-label">&nbsp;</label>
				<div class="layui-input-inline person" style="width: 650px">
					<table class="layui-table">
						<thead>
						<tr>
							<th>出行类型</th>
							<!--<th>价格</th>-->
							<th>车型</th>
						</tr>
						</thead>
						<tbody class="personchild">
							
							{volist name="vo['person'][0]" id="vo1"}
								<tr>
									<td>
										<input type="hidden" name="person_id" id="person_id" value="{$vo1.person_id}">
										<input readonly name="person_name" value="{$vo1.person_name}"  placeholder="出行类型" autocomplete="off" class="layui-input layui-col-xs5" type="text" lay-key="2">
									</td>
									<!--<td>-->
										<!--<input readonly name="person_price" value="{$vo1.person_price}"  placeholder="价格" autocomplete="off" class="layui-input layui-col-xs5" type="number" lay-key="2">-->
									<!--</td>-->
									<td>
										<select name="carType" id="" class="layui-select">
											{volist name='carTypeList' id='car'}
											<option value="{$car.cartype_id}" {if $car['cartype_id']==$vo1.car_type}selected{/if}>{$car.title}</option>
											{/volist}
										</select>
									</td>
								 </tr>
							{/volist}
						</tbody>
					</table>
				</div>
			</div>

		</div>
		{/volist}
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit lay-filter="admin">更新车型</button>
		</div>
	</div>

</form>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
	var message;
	layui.config({
		base: '__JS__/',
		version: '1.0.1'
	}).use(['app', 'message'], function() {
		var app = layui.app,
				$ = layui.jquery,
				layer = layui.layer;
		//将message设置为全局以便子页面调用
		message = layui.message;
		//主入口
		app.set({
			type: 'iframe'
		}).init();
	});
</script>
<script>
	layui.use(['layer', 'laydate', 'form'], function() {
		var layer = layui.layer,
				$ = layui.jquery,
				laydate = layui.laydate,
				form = layui.form;
		//提交表单
		form.on('submit(admin)', function(data) {
			var id = $("#classifyid").val(); //商品ID
			var data = [];
			var classifychild = $(".classifychild");
			for(var i = 0; i < classifychild.length; i++) {
				var datas = {};
				var datal = [];

				var personchild = $(classifychild[i]).find(".personchild tr");
				for(var k = 0; k < personchild.length; k++) {
					var datass = {};
					var person_id = $(personchild[k]).find("input[name=person_id]").val();
					if(person_id) {
						datass.person_id = person_id;
					}
					datass.car_type = $(personchild[k]).find("select[name=carType]").val();
					datal.push(datass);
				}
				datas.persondata = datal;
				data.push(datas);
			}
			$.ajax({
				url: "{:url('admin/goods/setgoodscartype')}",
				data: {
					id: id,
					data: data
				},
				type: 'post',
				async: false,
				success: function(res) {
					layer.msg(res.msg);
					if(res.code == 1) {
						setTimeout(function() {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
						}, 1000)
					}
				}
			})
			return false;
		})
	});
</script>
</body>
</html>